/*
 * Copyright (c) 2015, the Dart project authors.
 *
 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not use this file except
 * in compliance with the License. You may obtain a copy of the License at
 *
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License
 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied. See the License for the specific language governing permissions and limitations under
 * the License.
 */
package vm.element

// This file is generated by the script: pkg/vm_service/tool/generate.dart in dart-lang/sdk.

import com.google.gson.JsonObject

/**
 * {@link Breakpoint} 描述了一个调试器断点。
 */
class Breakpoint(json: JsonObject) : Obj(json) {

    /**
     * 一个标识此断点的数字。
     */
    fun getBreakpointNumber(): Int {
        return getAsInt("breakpointNumber")
    }

    /**
     * 此断点是否已启用？
     */
    fun getEnabled(): Boolean {
        return getAsBoolean("enabled")
    }

    /**
     * 这是否是一个作为 step OverAsyncSuspension resume 命令的一部分而合成添加的断点？
     *
     * 可以返回 <code>null</code>。
     */
    fun getIsSyntheticAsyncContinuation(): Boolean {
        return getAsBoolean("isSyntheticAsyncContinuation")
    }

    /**
     * 当断点被解析时为 SourceLocation，当断点未被解析时为 UnresolvedSourceLocation。
     *
     * @return <code>SourceLocation</code> 或 <code>UnresolvedSourceLocation</code> 之一
     */
    fun getLocation(): Any? {
        val elem = json.get("location")
        if (elem == null) return null

        if (elem.isJsonObject) {
            val o = elem.asJsonObject
            when (o.get("type").asString) {
                "SourceLocation" -> return SourceLocation(o)
                "UnresolvedSourceLocation" -> return UnresolvedSourceLocation(o)
            }
        }
        return null
    }

    /**
     * 此断点是否已分配给特定的程序位置？
     */
    fun getResolved(): Boolean {
        return getAsBoolean("resolved")
    }
}
